<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>小说阅读</title>
    <link rel="stylesheet" href="layui/css/layui.css" media="all"/>
    <style>
        body {
            font-family: 'Microsoft YaHei', sans-serif;
            text-align: left;
            color: #262626;
            background: rgb(208, 231, 188);
            -webkit-font-smoothing: antialiased;
            -moz-font-smoothing: antialiased;
        }

        .main-read-container {
            position: relative;
            z-index: 100;
            width: 940px;
            margin: 0 auto;
        }

        .read-main-wrap.font-family01 {
            font-family: 'Microsoft YaHei', sans-serif;
        }

        .read-main-wrap {
            font-family: 'Microsoft YaHei', sans-serif;
            font-size: 18px;
            width: 800px;
            margin: 0 auto;
        }
    </style>
</head>
<body>
<ul id="title" class="layui-nav" style="text-align: center ;" lay-filter="">
    <li class="layui-nav-item"><a href="novel_type.html">小说类型</a></li>
    <li class="layui-nav-item"><a href="novel_tag.html">小说标签</a></li>
    <li class="layui-nav-item layui-this"><a href="novel.html">小说详情</a></li>
    <li class="layui-nav-item"><a href="novel_chapter.html">小说章节</a></li>
</ul>

<div class="main-read-container">
    <div class="read-main-wrap font-family01" style="font-size: 18px; z-index: 101; ">

        <div id="test1" style="position: fixed; bottom: 0; "></div>

        <div id="content"></ul>
        </div>

    </div>

    <script src="layui/layui.js"></script>
    <script src="js/common.js"></script>
    <script>
        var request_url = BASE_URL + '/novel/content';

        layui.use(["laypage", 'jquery'], function () {
            var laypage = layui.laypage;
            var $ = layui.jquery

            var novelId = decodeURI(window.location.href.split('=')[1]).toString();
            var pageNum = 1;

            $.get(request_url, {pageNum: pageNum, pageSize: 1, novelId: novelId}, function (result) {
                res = result.data.list;
                console.log(res)

                if (res.length == 0) {
                    layer.open({
                        content: '本小说暂未收录',
                        yes: function (index, layero) {
                            layer.close(index);
                            window.location.href = "novel.html";
                        }
                    });
                }

                setHtml(res[0].chapterContent);
                setStyle(novelId);
                pages(result.data.total, novelId);
            });

            function pages(count, novelId) {
                laypage.render({
                    elem: 'test1'
                    , count: count
                    , theme: '#c00'
                    , layout: ['prev', 'page', 'next']
                    , limit: 1
                    , jump: function (obj, first) {
                        if (!first) {
                            $.post(request_url, {pageNum: obj.curr, pageSize: 1, novelId: novelId}, function (result) {
                                res = result.data.list;
                                console.log(res)
                                setHtml(res[0].chapterContent);
                                setStyle(novelId);
                                window.location.href = "#title"
                            });
                        }
                    }
                })
            }

            function setHtml(data) {
                document.getElementById('content').innerHTML = data.replace(/\n+/g, "<br/><br/>")
                    .replace(/\r+/g, "<br/><br/>").replace(/(\r\n)+/g, "<br/><br/>").replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;')
            }

            function setStyle(novelId) {
                $('#content').css({
                    "font-size": "large", "font-family": "'Courier New', Courier, monospace",
                    "color": "goldenrod;", "margin": "0 auto"
                });
            }
        });
    </script>
</body>
</html>
